﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using RESTReserva.Persistencia;
using RESTReserva.Dominio;
using System.ServiceModel.Web;
using System.Net;

namespace RESTReserva
{
    public class Reservas : IReservas
    {
        private ReservaDAO dao = new ReservaDAO();

        public Reserva CrearReserva(Reserva reservaACrear)
        {
           var existe = ObtenerReserva(reservaACrear);
            if (existe != null)
                throw new WebFaultException<string>("Ya existe una Reserva!!!", HttpStatusCode.NotFound);
            return dao.Crear(reservaACrear);
        }

        private object ObtenerReserva(Reserva reservaACrear)
        {
            return dao.ObtenerReserva(reservaACrear);
        }

        public Reserva ObtenerReserva(string codigo)
        {
            return dao.Obtener(codigo);
        }

        public List<Reserva> ListarReservas()
        {
            return dao.ListarTodos();
        }
    }
}
